package com.example.article.controller;


import com.example.api.common.R;
import com.example.api.entity.article.Article;
import com.example.article.service.ArticleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author lr
 * @since 2023-02-18
 */
@RestController
@RequestMapping("/article-t")
public class ArticleTController {

    @Resource
    private ArticleService articleTService;

    /**
     * 新增
     * @author zhengkai.blog.csdn.net
     * @date 2023/02/18
     **/
    @RequestMapping("/insert")
    public Object insert(Article articleT){
        return articleTService.insert(articleT);
    }

    /**
     * 新增
     * @author zhengkai.blog.csdn.net
     * @date 2023/02/18
     **/
    @GetMapping("/likeBlog")
    public Object likeBlog(@RequestParam("id") String id,@RequestParam("userId") String userId){
        return articleTService.likeBlog(id,userId);
    }

    /**
     * 刪除
     * @author zhengkai.blog.csdn.net
     * @date 2023/02/18
     **/
    @RequestMapping("/delete")
    public R delete(int id){
        return R.ok(articleTService.delete(id));
    }

    /**
     * 更新
     * @author zhengkai.blog.csdn.net
     * @date 2023/02/18
     **/
    @RequestMapping("/update")
    public R update(Article articleT){
        return R.ok(articleTService.update(articleT));
    }

    /**
     * 查询 根据主键 id 查询
     * @author zhengkai.blog.csdn.net
     * @date 2023/02/18
     **/
    @RequestMapping("/load")
    public Object load(int id){
        return R.ok(articleTService.load(id));
    }

    /**
     * 查询 分页查询
     * @author zhengkai.blog.csdn.net
     * @date 2023/02/18
     **/
    @RequestMapping("/pageList")
    public R pageList(@RequestParam(required = false, defaultValue = "0") int offset,
                                        @RequestParam(required = false, defaultValue = "10") int pagesize) {
        return R.ok(articleTService.pageList(offset, pagesize));
    }
}
